export default {
    data() {
        return {
            //页面栈
            pageStack: []
        }
    },
    computed: {
        curPage() {
            const len = this.pageStack.length;
            return len ? this.pageStack[len - 1].name : ''
        }
    },
    methods: {
        //前往
        go(name, data) {
            if (this.goBefore(name, data)) return
            this.pageStack.push({
                name,
                data
            })
            this.goAfter(name, data)
        },
        //清空栈
        cleanStack() {
            this.pageStack = this.pageStack.slice(0, 1);
        },
        //前置钩子
        goBefore(name, data) { console.log(name, data) },
        // 后置钩子
        goAfter(name, data) { console.log(name, data) },
        //判断是否为当前页
        isCurPage(name) {
            const cur = this.pageStack.pop();
            const isCur = cur && cur.name === name;
            this.pageStack.push(cur);
            return isCur;
        },
        //后退
        goBack() {
            if (this.pageStack.length > 1) {
                this.pageStack = this.pageStack.slice(0, -1)
            }
        }
    }
}